package com.bookstore.backend.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bookstore.backend.model.ResultVO;
import com.bookstore.backend.model.entity.Book;
import com.bookstore.backend.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: world
 * @date: 2022/7/29 15:10
 * @description: 测试接口
 */
@RestController
@RequestMapping("/book")
public class BookController {

    @Autowired
    private BookService bookService;

    //根据isbn查询
    @RequestMapping(value = "/select",method = RequestMethod.GET)
    public ResultVO<?> selectList(String isbn){
        return ResultVO.success(bookService.selectList(isbn));
    }

    @RequestMapping(value = "/page",method = RequestMethod.GET)
    public ResultVO<Page<Book>> tableController(@RequestParam(value = "page",defaultValue = "1")Integer page, @RequestParam(value = "size",defaultValue = "5")Integer size){
        Page<Book> bookPage = new Page<Book>(page,size);
        Page<Book> result = bookService.page(bookPage);
        return ResultVO.success(result);
    }

    //添加
    @PostMapping("/insert")
    public ResultVO<?> insert(@RequestBody Book book){
        return ResultVO.success(bookService.insert(book));
    }

    //更新
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public ResultVO<?> updateNumBybid(@RequestBody Book book){return ResultVO.success(bookService.updateNumBybid(book));}

    //删除
    @RequestMapping(value = "/delete",method = RequestMethod.DELETE)
    public  ResultVO<?> deleteNumBybid(Integer bid){
        return ResultVO.success(bookService.deleteNumBybid(bid));
    }
}
